#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QJsonArray>
#include <QJsonObject>
#include <QJsonParseError>
#include <QMouseEvent>
#include "weatherData.h"


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowFlag(Qt::FramelessWindowHint);           //去掉原本的窗口边缘

    quitMenu = new QMenu(this);         //创建一个QMenu对象
    quitAct = new QAction(QIcon(":/widget/quit.png"), tr("退出"), this);     //定义一个退出动作
    quitMenu->addAction(quitAct);       //添加动作

    //    connect(quitMenu,&QMenu::triggered,this,[=]{
    //        this->close();
    //    });         //连接信号与槽

    //将控件添加到数组

    // 星期列表（7个控件：0-6）
    weekList << ui->labelDay0 << ui->labelDay1<< ui->labelDay2 << ui->labelDay3
             << ui->labelDay4 << ui->labelDay5<< ui->labelDay6;

    // 日期列表（7个控件：0-6）
    dateList << ui->labelDate0 << ui->labelDate1<< ui->labelDate2 << ui->labelDate3
             << ui->labelDate4 << ui->labelDate5<< ui->labelDate6;

    // 天气列表（7个控件：0-6）
    weatherList << ui->labelWeatherDay0 << ui->labelWeatherDay1<< ui->labelWeatherDay2 << ui->labelWeatherDay3
                << ui->labelWeatherDay4 << ui->labelWeatherDay5<< ui->labelWeatherDay6;

    // 天气图标列表（7个控件：0-6）
    weatherIconList << ui->labelWeatherIcon0 << ui->labelWeatherIcon1<< ui->labelWeatherIcon2 << ui->labelWeatherIcon3
                    << ui->labelWeatherIcon4 << ui->labelWeatherIcon5 << ui->labelWeatherIcon6;

    // 空气污染列表（7个控件：0-6）
    airPollutionList << ui->labelAirquality0 << ui->labelAirquality1<< ui->labelAirquality2 << ui->labelAirquality3
                     << ui->labelAirquality4 << ui->labelAirquality5<< ui->labelAirquality6;

    // 风的类型列表（7个控件：0-6）注意控件命名一致性
    windDirectionList << ui->labelWindDirection0 << ui->labelWindDirection1 << ui->labelWindDirection2 << ui->labelWindDirection3
                 << ui->labelWindDirection4 << ui->labelWindDirection5<< ui->labelWindDirection6;

    // 风力列表（7个控件：0-6）注意控件命名一致性
    windPowerList << ui->labelWindPower0 << ui->labelWindPower1<< ui->labelWindPower2 << ui->labelWindPower3
                  << ui->labelWindPower4 << ui->labelWindPower5<< ui->labelWindPower6;
    //天气类型图标
    weatherIconMap.insert("晴", ":/weatherIcon/Qing.png");
    weatherIconMap.insert("多云", ":/weatherIcon/DuoYun.png");
    weatherIconMap .insert("阴", ":/weatherIcon/Yin.png");
    weatherIconMap.insert("雨", ":/weatherIcon/Yu.png");
    weatherIconMap.insert("雪", ":/weatherIcon/Xue.png");
    weatherIconMap.insert("沙尘暴", ":/weatherIcon/ShaChenBao.png");

    weatherIconMap.insert("雷阵雨", ":/weatherIcon/LeiZhenYu.png");
    weatherIconMap.insert("大雨", ":/weatherIcon/DaYu.png");
    weatherIconMap.insert("小雨", ":/weatherIcon/XiaoYu.png");
    weatherIconMap.insert("中雨", ":/weatherIcon/ZhongYu.png");
    weatherIconMap.insert("阵雨", ":/weatherIcon/ZhenYu.png");
    weatherIconMap.insert("暴雨", ":/weatherIcon/BaoYu.png");
    weatherIconMap.insert("大暴雨", ":/weatherIcon/DaBaoYu.png");
    weatherIconMap.insert("大到暴雨", ":/weatherIcon/DaDaoBaoYu.png");
    weatherIconMap.insert("暴雨到大暴雨", ":/weatherIcon/BaoYuDaoDaBaoYu.png");
    weatherIconMap.insert("大暴雨到特大暴雨", ":/weatherIcon/DaBaoYuDaoTeDaBaoYu.png");

    weatherIconMap.insert("暴雪", ":/weatherIcon/BaoXue.png");
    weatherIconMap.insert("大到暴雪", ":/weatherIcon/DaDaoBaoXue.png");
    weatherIconMap.insert("大雪", ":/weatherIcon/DaXue.png");
    weatherIconMap.insert("小雪", ":/weatherIcon/XiaoXue.png");
    weatherIconMap.insert("中雪", ":/weatherIcon/ZhongXue.png");

    weatherIconMap.insert("霾", ":/weatherIcon/Mai.png");
    weatherIconMap.insert("扬沙", ":/weatherIcon/YangSha.png");
    weatherIconMap.insert("特大暴雨", ":/weatherIcon/TeDaBaoYu.png");
    weatherIconMap.insert("雾", ":/weatherIcon/Wu.png");
    weatherIconMap.insert("小到中雨", ":/weatherIcon/XiaoDaoZhongYu.png");
    weatherIconMap.insert("小到中雪", ":/weatherIcon/XiaoDaoZhongXue.png");
    weatherIconMap .insert("雨夹雪", ":/weatherIcon/YuJiaXue.png");
    weatherIconMap.insert("阵雪", ":/weatherIcon/ZhenXue.png");
    connect(quitMenu,&QMenu::triggered,this,&MainWindow::onQuitActTriggered);   //连接菜单被触发的信号与槽

    NetAccessManger = new QNetworkAccessManager(this);          //实例化一个网络请求对象

    connect(NetAccessManger,&QNetworkAccessManager::finished,this,&MainWindow::readHttpReply);  //连接网络请求获取的信号与槽

    //101010100是北京的城市编码
//    getWeatherInfo("101010100");       //获取城市

    //给标签添加事件过滤器
    ui->higntTemLabel->installEventFilter(this);        //高温事件过滤器
    ui->lowTemLabel->installEventFilter(this);          //低温事件过滤器


}

MainWindow::~MainWindow()
{
    delete ui;
}

//鼠标点击
void MainWindow::mousePressEvent(QMouseEvent *event)
{
    //如果右键被按下
    if(event->button() == Qt::RightButton)
    {
        quitMenu->exec(QCursor::pos());       //在当前鼠标位置显示菜单
    }

    //当前鼠标位置 event->globalPos()
    //当前窗口位置 this->pos()
    if(event->button() == Qt::LeftButton)
    {
        moffset = event->globalPos() - this->pos();
    }
}

//鼠标移动
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
    this->move(event->globalPos() - moffset);    //移动窗口
}

//弹窗
bool MainWindow::closePOPWindow()
{
    // 创建一个消息框询问用户是否真的要退出
    QMessageBox mes;
    mes.setWindowTitle("关闭窗口");
    //  mes.setWindowFlags(Qt::Drawer);       //把标题栏去掉
    mes.setIcon(QMessageBox::Warning);    //设置一个警告图片
    mes.setText("是否关闭窗口？");          //弹窗文本

    mes.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);     //设置两个按钮
    mes.setWindowIcon(QIcon(":/widget/dog.png")); // 设置窗口图标
    mes.setButtonText(QMessageBox::Ok, tr("确定"));               //ok改为确认
    mes.setButtonText(QMessageBox::Cancel, tr("取消"));           //Cancel改为取消

    // 显示消息框并等待用户交互
    int result = mes.exec();

    // 根据用户的选择执行相应的操作
    if (result == QMessageBox::Ok) {
        // 用户选择了确定，关闭主窗口
        this->close();
        return true;
    }
    // 用户选择了取消，不关闭主窗口
    else
    {
        return false;     // 窗口关闭操作失败
    }
}

//右上角退出
void MainWindow::on_pushButton_quit_clicked()
{
    closePOPWindow();
}

//鼠标右键退出
void MainWindow::onQuitActTriggered()
{
    closePOPWindow();
}


//获取天气数据
void MainWindow::getWeatherInfo(QString cityName)
{

    QString cityCode;       //城市编码

    //输入纯数字城市编码，直接使用
    bool isNumber;
    cityName.toInt(&isNumber);        //将城市名转换为整数，结果存在isNumber中

    //如果是纯数字，直接作为城市编码用
    if(isNumber)
    {
        cityCode = cityName;        //使输入的数字作为城市编码
    }
    else        //如果不是纯数字
    {
        cityCode = CityToCityCode::citySearch(cityName);            //通过城市名称查询城市编码
    }

    qDebug() << "输入城市名" << cityName;
    qDebug() << "城市编码" << cityCode;

    //检查城市名称是否为空
    if (cityName.isEmpty()) {
        QMessageBox::warning(this, "警告", "输入城市不能为空");     //先手警告框
        return;
    }


//    QString cityCode = CityToCityCode::citySearch(cityName);

//    qDebug() << cityCode;

    QUrl url("http://t.weather.itboy.net/api/weather/city/" + cityCode);

//    QUrl url(QString("http://t.weather.itboy.net/api/weather/city/").arg(cityCode));
    qDebug() << "请求URL：" << url.toString();

    qDebug() << "Request URL:" << url; // 调试输出
    NetAccessManger->get(QNetworkRequest(url));                    //发送GET请求，获取数据

}

//解析JSON格式天气数据
void MainWindow::parseJson(QByteArray &byteArray)
{
    //错误
    QJsonParseError err;        //创建一个错误对象
    QJsonDocument doc = QJsonDocument::fromJson(byteArray, &err);   //将JSON格式解析为QJsonDocument对象
    //如果错误
    if(err.error != QJsonParseError::NoError)
    {
        return;    //返回
    }

    QJsonObject rootObj = doc.object();     //创建一个QJsonObject对象返回文档
    //    qDebug() << rootObj.value("message").toString();

    //1.解析城市和日期
    today.city = rootObj.value("cityInfo").toObject().value("city").toString();     //城市
    today.date = rootObj.value("date").toString();                                  //日期

//    // 2. 初始化 day 数组（至少包含 7 天：昨天 + 未来6天）
//    day.clear(); // 清空旧数据
//    day.resize(7); // 预分配空间（最多7天）

    //2.解析昨天yesterday数据
    QJsonObject objData = rootObj.value("data").toObject();         //获取data对象

    QJsonObject objYesterday = objData.value("yesterday").toObject();          //昨天
    if(!objYesterday.isEmpty())
    {
        day[0].week = objYesterday.value("week").toString();                       //星期
        day[0].date = objYesterday.value("ymd").toString();                       //日期
        qDebug() << "day[0].date parsed:" << day[0].date; // 添加调试输出



        day[0].weatherType = objYesterday.value("type").toString();                      //天气类型

        QString highT;          //最高温
        highT = objYesterday.value("high").toString().split(" ").at(1); //空格分割，取分割后第二个数据，1是第二个，0是第一个
        day[0].highTem = highT.left(highT.length() - 1).toInt(); //把℃减掉，只剩数字
        QString lowT;           //最低温
        lowT = objYesterday.value("low").toString().split(" ").at(1);
        day[0].lowTem = lowT.left(lowT.length() - 1).toInt();

        //风的类型，风力
        day[0].windType = objYesterday.value("fx").toString();      //风的类型
        day[0].windPower = objYesterday.value("fl").toString();     //风力

        //空气指数
        day[0].airQuality =objYesterday.value("aqi").toDouble();    //空气质量

    }
    //3.解析未来几天的天气数据
    QJsonArray forecastArray = objData.value("forecast").toArray();        //获取forecast数组
    //遍历未来几天天气数据
    int loopCount = qMin(forecastArray.size(),  6);
    for(int i=0 ; i<loopCount ; i++)
    {
        QJsonObject forecastObj = forecastArray[i].toObject();             //获取JSON对象

        day[i+1].week = forecastObj.value("week").toString();             //星期
        day[i+1].date = forecastObj.value("ymd").toString();              //日期
        day[i+1].weatherType = forecastObj.value("type").toString();      //天气类型
        //空气指数
        day[i+1].airQuality =forecastObj.value("aqi").toDouble();         //空气质量


        QString highT;      //最高温
        highT = forecastObj.value("high").toString().split(" ").at(1);      //空格分割，取分割后第二个数据，1是第二个，0是第一个
        day[i+1].highTem = highT.left(highT.length() - 1).toInt();          //把℃减掉，只剩数字
        QString lowS;       //最低温
        lowS = forecastObj.value("low").toString().split(" ").at(1);
        day[i+1].lowTem = lowS.left(lowS.length() - 1).toInt();

        //风的类型，风力
        day[i+1].windType = forecastObj.value("fx").toString();           //风的类型
        day[i+1].windPower = forecastObj.value("fl").toString();          //风力

    }
    //4、解析今天的数据
    today.temperature =objData.value("wendu").toString().toDouble();                 //温度
    today.temperature = static_cast<int>(today.temperature );       //强制转为整数
    qDebug() << "today.Temperature  = " << today.temperature ;

    today.ganMao =objData.value("ganmao").toString();                  //感冒指数+

    today.Humidity = objData.value("shidu").toString();                //湿度
    today.PM25 = objData.value("pm25").toDouble();                        //PM2.5
    today.airQuality = objData.value("quality").toString();            //空气质量

    //5、forecast里面也有今天的数据

    // 5. 确保 today 的数据与 forecast[0] 一致（今天）
    if (loopCount > 0) {
        today.weatherType = day[1].weatherType;
        today.highTem = day[1].highTem;
        today.lowTem = day[1].lowTem;
        today.windType = day[1].windType;
        today.windPower = day[1].windPower;
    }

    //6、更新UI界面
    updateUI();

}

//更新UI界面
void MainWindow::updateUI()
{
    // 当前日期处理
    QDate currentDate = QDate::fromString(today.date, "yyyyMMdd");
    if (!currentDate.isValid()) {
        qWarning() << "Invalid current date:" << today.date;
        return;
    }
    ui->labelCurrentDate->setText(currentDate.toString("yyyy/MM/dd") + " " + day[1].week);

    ui->labelCity->setText(today.city);     //城市
//    ui->labelCurrentDate->setText(QDateTime::fromString(today.date,"yyyyMMdd").toString("yyyy/MM/dd")
//                                  + " " + day[1].week);  //当前日期

//    ui->labelCity->setText(today.city);         //城市

    //今天
    ui->labelWeatherTypeP->setPixmap(weatherIconMap[today.weatherType]);   //天气图标
    ui->labelTemperature->setText(QString::number(today.temperature)+"℃");     //温度
    qDebug() <<today.temperature;
    ui->labelWeatherType->setText(today.weatherType);           //天气类型
    ui->labelTemperatureRange->setText(QString::number(today.lowTem) + "~" + QString::number(today.highTem) + "℃"); //温度范围

    ui->labelTips->setText(today.ganMao);               //天气小提示
    ui->labelWindTy->setText(today.windType);           //风的类型
    ui->labelWindPr->setText(today.windPower);          //风力
    ui->labelPM25Pr->setText(QString::number(today.PM25));                 //PM2.5
    ui->labelHumidityPr->setText(today.Humidity);                          //湿度
    ui->labelAirqualityPr->setText(today.airQuality);                        //空气质量

    //更新未来几天
//    const int maxDay = 7;
    const int maxDay = qMin(7, qMin(qMin(weekList.size(),  dateList.size()),
                                 qMin(qMin(weatherList.size(),  weatherIconList.size()),
                                 qMin(qMin(airPollutionList.size(),  windDirectionList.size()),
                                      windPowerList.size()))));
    for(int i = 0; i < maxDay; i++)
    {
        qDebug() << "Updating index:"<< i << ", date:" << day[i].date;
        // 边界检查
             if (i >= 7 || i >= weekList.size() || i >= dateList.size() ||
                 i >= weatherList.size() || i >= weatherIconList.size() ||
                 i >= airPollutionList.size() || i >= windDirectionList.size() ||
                 i >= windPowerList.size()) {
                 qWarning() << "Index out of range:" << i;
                 continue;
             }
        // 设置昨天、今天、明天等标签
        if(i == 0) {
            weekList[i]->setText("昨天"); // 直接设置第一天为昨天
        } else if(i == 1) {
            weekList[i]->setText("今天");
        } else if(i == 2) {
            weekList[i]->setText("明天");
        } else {
            weekList[i]->setText(day[i].week); // 后续显示实际星期
        }


        //日期 2025-1-28
//        QStringList ymdList = day[i].date.split("-");               //-作为分隔符
//        qDebug() << day[i].date;
//        dateList[i]->setText(ymdList[1] + "/" + ymdList[2]);        //取月份和日期 1/28
        // 设置日期
        QStringList ymdList = day[i].date.split("-");
        if (ymdList.size() >= 3) {
            dateList[i]->setText(ymdList[1] + "/" + ymdList[2]);
        } else {
            dateList[i]->setText("N/A");
        }

        //天气类型
        weatherList[i]->setText(day[i].weatherType);        //天气
        weatherIconList[i]->setPixmap(weatherIconMap[day[i].weatherType]);      //天气图标

        //空气质量
        if(day[i].airQuality >= 0 && day[i].airQuality<=50)
        {
            airPollutionList[i]->setText("优");
            airPollutionList[i]->setStyleSheet("background-color: rgb(70, 211, 103);");
        }
        else if(day[i].airQuality > 50 && day[i].airQuality <= 100)
        {
            airPollutionList[i]->setText("良");
            airPollutionList[i]->setStyleSheet("background-color: rgb(255, 199, 69);");
        }
        else if(day[i].airQuality > 100 && day[i].airQuality <= 150)
        {
            airPollutionList[i]->setText("轻度");
            airPollutionList[i]->setStyleSheet("background-color: rgb(255, 199, 69);");
        }
        else if(day[i].airQuality > 150 && day[i].airQuality <= 200)
        {
            airPollutionList[i]->setText("中度");
            airPollutionList[i]->setStyleSheet("background-color: rgb(255, 85, 0);");
        }
        else if(day[i].airQuality > 200 && day[i].airQuality <= 250)
        {
            airPollutionList[i]->setText("重度");
            airPollutionList[i]->setStyleSheet("background-color: rgb(255, 0, 0);");
        }
        else
        {
            airPollutionList[i]->setText("严重");
            airPollutionList[i]->setStyleSheet("background-color: rgb(203, 0, 0);");
        }

        //风
        windDirectionList[i]->setText(day[i].windType);              //风向
        windPowerList[i]->setText(day[i].windPower);            //风力
    }

    //不添加温度就会显示为0℃
    ui->higntTemLabel->update();
    ui->lowTemLabel->update();

}

//网络请求获取
void MainWindow::readHttpReply(QNetworkReply *reply)
{
    int status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();   //状态码

    //请求错误
    if(reply->error() != QNetworkReply::NoError || status_code != 200)
    {
        qDebug() << reply->errorString().toLatin1().data();     //打印错误信息
        QMessageBox::warning(this,"天气","请求数据失败", QMessageBox::Ok);      //弹出警告信息框
    }
    //请求成功
    else
    {
        QByteArray byteArray = reply->readAll();        //读取服务器数据
        qDebug() << "read all:"<< byteArray.data();     //打印接收到的数据
        parseJson(byteArray);                           //解析JSON数据
    }
    reply->deleteLater();       //释放对象
}

//搜索按钮
void MainWindow::on_pushButtonSearch_clicked()
{
    QString inputCity = ui->lineEditSearch->text().trimmed(); // 获取并清理输入
    if (inputCity.isEmpty()) {
        QMessageBox::warning(this, "提示", "请输入城市名称");
        return;
    }

    // 转换为城市编码
    QString cityCode = CityToCityCode::citySearch(inputCity);
    if (cityCode.isEmpty()) {
        QMessageBox::warning(this, "错误", "未找到该城市：" + inputCity);
        return;
    }

    // 使用编码获取天气
    getWeatherInfo(inputCity);
}

//事件过滤
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
    if(event->type() == QEvent::Paint)
    {
        //"watched" 是否等于 "ui->higntTemLabel"，来判断是否是标签控件 "ui->lowTemLabel" 的绘图事件
        if(watched == ui->higntTemLabel)
        {
            paintHightTemCure();
        }

        if(watched == ui->lowTemLabel)
        {
            paintLowTemCure();
        }
    }
    return QWidget::eventFilter(watched,event);

}

//绘制高温曲线
void MainWindow::paintHightTemCure()
{
    QPainter painter(ui->higntTemLabel);    // 创建一个QPainter对象，将ui->higntTemLabel作为绘图设备

    //抗锯齿
    painter.setRenderHint(QPainter::Antialiasing,true);

    //1、获取x坐标
    int pointX[7] = {0};        //定义一个数组存储温度x坐标
    //遍历7个点
    for(int i=0; i<7;i++)
    {
        pointX[i] = windDirectionList[i]->pos().x() + windDirectionList[i]->width()/2;;
    }


    //获取y坐标
    int tempSum = 0;         //高温总和
    int tempAverage = 0;    //高温平均值

    for(int i=0; i<7; i++)
    {
        tempSum += day[i].highTem;      //7天高温值的总和
    }
    tempAverage = tempSum/7;            //7天温度平均值

    //计算Y坐标
    int pointY[7] = {0};        //7个y点坐标

    int centerY = ui->higntTemLabel->height()/2;    //高温标签y的中心坐标
    for(int i=0; i<7; i++)
    {
        pointY[i] = centerY - ((day[i].highTem-tempAverage)*INCREMENT);    //获得7个点y坐标
    }

    //开始绘制
    //初始化画笔
    QPen pen = painter.pen();                //获得画笔
    pen.setWidth(1);                        //画笔宽度
    pen.setColor(QColor(45,224,217));       //设置画笔颜色

    painter.setPen(pen);            //设置画笔
    painter.setBrush(QColor(45,224,217));       //设置画刷，内部填充颜色

    //画点，画文本
    for(int i=0; i<7; i++)
    {
        painter.drawEllipse(QPoint(pointX[i],pointY[i]), POINT_RADIUS,POINT_RADIUS);    //画7个点的圆圈


        //显示文本
        painter.drawText(pointX[i]-OFFSET_X,pointY[i]-OFFSET_Y,QString::number(day[i].highTem) + "℃");
    }

    //绘制曲线
    for(int i=0; i < 6; i++)
    {
        if(i==0)
        {
            pen.setStyle(Qt::DotLine);      //画虚线
            painter.setPen(pen);            //设置画笔
        }
        else
        {
            pen.setStyle(Qt::SolidLine);     //画实线
            painter.setPen(pen);             //设置画笔
        }

        painter.drawLine(pointX[i],pointY[i],pointX[i+1],pointY[i+1]);      //画7天的线
    }

}

//绘制低温曲线
void MainWindow::paintLowTemCure()
{
    QPainter painter(ui->lowTemLabel);    // 创建一个QPainter对象，将ui->higntTemLabel作为绘图设备

    //抗锯齿
    painter.setRenderHint(QPainter::Antialiasing,true);

    //1、获取x坐标
    int pointX[7] = {0};        //定义一个数组存储温度x坐标
    //遍历7个点
    for(int i=0; i<7;i++)
    {
        pointX[i] = windDirectionList[i]->pos().x() + windDirectionList[i]->width()/2;;
    }


    //获取y坐标
    int tempSum = 0;         //高温总和
    int tempAverage = 0;    //高温平均值

    for(int i=0; i<7; i++)
    {
        tempSum += day[i].lowTem;      //7天高温值的总和
    }
    tempAverage = tempSum/7;            //7天温度平均值

    //计算Y坐标
    int pointY[7] = {0};        //7个y点坐标

    int centerY = ui->lowTemLabel->height()/2;    //高温标签y的中心坐标
    for(int i=0; i<7; i++)
    {
        pointY[i] = centerY - ((day[i].lowTem-tempAverage)*INCREMENT);    //获得7个点y坐标
    }

    //开始绘制
    //初始化画笔
    QPen pen = painter.pen();                //获得画笔
    pen.setWidth(1);                        //画笔宽度
    pen.setColor(QColor(255,223,0));       //设置画笔颜色

    painter.setPen(pen);            //设置画笔
    painter.setBrush(QColor(255,223,0));       //设置画刷，内部填充颜色

    //画点，画文本
    for(int i=0; i<7; i++)
    {
        painter.drawEllipse(QPoint(pointX[i],pointY[i]), POINT_RADIUS,POINT_RADIUS);    //画7个点的圆圈

//        qDebug() << day[i].lowTem;
        //显示文本
        painter.drawText(pointX[i]-OFFSET_X,pointY[i]-OFFSET_Y,QString::number(day[i].lowTem) + "℃");
    }

    //绘制曲线
    for(int i=0; i < 6; i++)
    {
        if(i==0)
        {
            pen.setStyle(Qt::DotLine);      //画虚线
            painter.setPen(pen);            //设置画笔
        }
        else
        {
            pen.setStyle(Qt::SolidLine);     //画实线
            painter.setPen(pen);             //设置画笔
        }

        painter.drawLine(pointX[i],pointY[i],pointX[i+1],pointY[i+1]);      //画7天的线
    }

}
